import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import tailwindcss from "@tailwindcss/vite";
import path from 'path';
const host = process.env.TAURI_DEV_HOST;
const VITE_BASEES_URL = "http://127.0.0.1:8095";
// const VITE_BASEES_URL = "http://yy.anyi14.top";
// https://vitejs.dev/config/
export default defineConfig(async () => ({
  plugins: [vue(), tailwindcss()],

  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  clearScreen: false,
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  server: {
    port: 1420,
    proxy: {
      "/api": {
        target: VITE_BASEES_URL,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, "")
      },
    },
    strictPort: true,
    host: host || false,
    hmr: host
      ? {
          protocol: "ws",
          host,
          port: 1421,
        }
      : undefined,
    watch: {
      // 3. tell vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"],
    },
  },
}));
